package com.gz.EuchreU.Controls;

import org.anddev.andengine.entity.Entity;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.Scene.ITouchArea;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.text.Text;
import org.anddev.andengine.input.touch.TouchEvent;

import com.gz.EuchreU.Contants.UI;

public abstract class UIButton extends Entity{

	
	public UIButton(String pText, final float pX, final float pY, final float pWidth, int pTextureID, Scene pScene){
		float height = UI.getTextures().getHeightFromWidth(pTextureID, pWidth);
		final Sprite mBackground = new Sprite(pX,pY,pWidth,height,UI.getTextures().getTexture(pTextureID)){
			@Override
			public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
					float pTouchAreaLocalX, float pTouchAreaLocalY) {
				if(pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP){
						return OnTouched();
				}
				else return true;
			}
		};
		final Text mText = new Text(pX,pY,UI.getTextures().getFont(),pText){
			@Override
			public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
					float pTouchAreaLocalX, float pTouchAreaLocalY) {
				if(pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP){
					return OnTouched();
				}
				else return true;
			}
		};
		
		mText.setPosition(pX + (pWidth - mText.getWidth())/2, pY + (height - mText.getHeight())/2);
		
		attachChild(mBackground);
		attachChild(mText);
		
		pScene.registerTouchArea(mBackground);
		pScene.registerTouchArea(mText);
	}

	public abstract boolean OnTouched();//{
//		return false;
//	}
	
	public boolean contains(float pX, float pY) {
		// TODO Auto-generated method stub
		return false;
	}
	
}
